package com.hexinfo.dmpro.admin.security;

import com.hexinfo.dmpro.common.cache.CacheFactory;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * Token配置器
 */
public class TokenConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    private final TokenProvider tokenProvider;

    private final CacheFactory cacheFactory;

    public TokenConfigurer(TokenProvider tokenProvider, CacheFactory cacheFactory) {
        this.tokenProvider = tokenProvider;
        this.cacheFactory = cacheFactory;
    }

    @Override
    public void configure(HttpSecurity http) {
        TokenFilter customFilter = new TokenFilter(tokenProvider, cacheFactory);
        http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
    }
}
